import { Input, Space, Table } from 'antd';
import React, { useEffect,useState } from "react";
import { inject, observer } from 'mobx-react';
import MyPage from './../common/MyPagination.jsx';
import './../../assets/css/knowledge/common.css'


const IndustryAnalysis = (props) => {
  const columns = [
    {
      title: '分类',
      dataIndex: 'sort',
      key:'sort',
    },
    {
      title: '标题',
      dataIndex: 'title',
      key:'title',
      render: (text) => <span className='knowledgeA'>{text}</span>,
    },
    {
      title: '内容概要',
      dataIndex: 'outline',
      key:'outline',
    },
    {
      title: '发布人',
      dataIndex: 'user_name',
      key:'user_name',
    },
    {
      title: '发布时间',
      dataIndex: 'pubdate',
      key:'pubdate',
    },
    {
      title: '管理',
      key: 'action',
      render: (_, record) => { 
        return (
          <Space size="middle">
            <button className='BtnUpdate'>修改</button>
            <button className='BtnDel' onClick={() => delect(record)} >删除</button>
          </Space>
        )
      }
    }
  ];
  //删除
  let delect = (record) => {
    let id = record.k_id;
    console.log('id', id);
    props.knowledgeStore.delListData({ currentPage: 1, pageSize: 10, k_id: id }).then(() => {
      props.knowledgeStore.getSaleIndustryListData({ currentPage: 1, pageSize: 10, sort: '行业分析' })
    })
  }
   //获取查询input框的值
  const [resInput, setResInput] = useState('')
  const { Search } = Input;
  const OnSearch = (value) => {
    setResInput(value)
  };

  useEffect(() => {
    if (resInput === '') {
      props.knowledgeStore.getSaleIndustryListData({ currentPage: 1, pageSize: 10 ,sort:'行业分析'});
    } else { 
      props.knowledgeStore.getSearchListData({ currentPage: 1, pageSize: 10, title: resInput });
    }
  }, [resInput]);
 

  return(
    <div>
      <div className='knoweledgeSearch'>
        快速搜索：
        <Space direction="horizontal" >
          <Search 
            placeholder="关键词"
            allowClear
            enterButton="Search"
            onSearch={OnSearch}
            spellCheck='false'
          />
        </Space>
      </div>
      <Table 
          //  rowSelection={{
          //   ...rowSelection,
          // }}        
          columns={columns}
          dataSource={props.knowledgeStore.data}
          pagination={false}
      />
      <MyPage/>
    </div>
  );
} 

export default inject('knowledgeStore')(observer(IndustryAnalysis)) ;
